package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbDynamicImage;
import com.ruoyi.system.service.ITbDynamicImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 动态图片Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/image")
public class TbDynamicImageController extends BaseController
{
    @Autowired
    private ITbDynamicImageService tbDynamicImageService;

    /**
     * 查询动态图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDynamicImage tbDynamicImage)
    {
        startPage();
        List<TbDynamicImage> list = tbDynamicImageService.selectTbDynamicImageList(tbDynamicImage);
        return getDataTable(list);
    }

    /**
     * 导出动态图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:export')")
    @Log(title = "动态图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDynamicImage tbDynamicImage)
    {
        List<TbDynamicImage> list = tbDynamicImageService.selectTbDynamicImageList(tbDynamicImage);
        ExcelUtil<TbDynamicImage> util = new ExcelUtil<TbDynamicImage>(TbDynamicImage.class);
        util.exportExcel(response, list, "动态图片数据");
    }

    /**
     * 获取动态图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbDynamicImageService.selectTbDynamicImageById(id));
    }

    /**
     * 新增动态图片
     */
    @PreAuthorize("@ss.hasPermi('system:image:add')")
    @Log(title = "动态图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDynamicImage tbDynamicImage)
    {
        return toAjax(tbDynamicImageService.insertTbDynamicImage(tbDynamicImage));
    }

    /**
     * 修改动态图片
     */
    @PreAuthorize("@ss.hasPermi('system:image:edit')")
    @Log(title = "动态图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDynamicImage tbDynamicImage)
    {
        return toAjax(tbDynamicImageService.updateTbDynamicImage(tbDynamicImage));
    }

    /**
     * 删除动态图片
     */
    @PreAuthorize("@ss.hasPermi('system:image:remove')")
    @Log(title = "动态图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbDynamicImageService.deleteTbDynamicImageByIds(ids));
    }
}
